package mspdt.ubzuuch.mn;

import java.text.NumberFormat;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.taptwo.android.widget.CircleFlowIndicator;
import org.taptwo.android.widget.ViewFlow;
import org.taptwo.android.widget.ViewFlow.ViewSwitchListener;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.ImageView;
import android.widget.TextView;

public class ViewActivity extends Activity{
	
	private ViewFlow gallery;
	private CircleFlowIndicator indicator;
	private String name, body, price, image, roomnum, sq, internet, security, cable, tavilga, togloom, domofon, hashaa, garaj, duureg, yavts, 
						streetimage, davuutal, tolbor, holboobarih, video, barilgaimage, dundsurguuli, tsetserleg, ihsurguuli, category;
	private String lat, lan, room_image, bair_image;
	private ArrayList<String> images = new ArrayList<String>();
	private TextView tv_name;
	private GalleryAdapter gal_adapter;
	private int tv_id =0;
	private ExpandableListView exp_view;
	private MainExpandableAdapter view_adapter;
	private ArrayList<String> parent_datas = new ArrayList<String>();
	private ArrayList<ArrayList<String>> child_datas = new ArrayList<ArrayList<String>>();
	private String b_id = "";
	private String[] parent_names = {"Мэдээлэл", "Үнэ","Ойрхон сургууль цэцэрлэг"};
	private int gal_pos = 0;
	private TextView full_screen;
	private DBAdapter db;
	private boolean isFromFB = true;
	private int item_id = 0;
	private NetworkConnectionClass network;
	Activity va;
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.item_view);
		initialize();
		
		//focusOnView();
		db = new DBAdapter(this);
		if(isFromFB)
		{
			loadDataFromDB();
		}
		else
		{
			findViewById(tv_id).setBackgroundResource(R.drawable.text_background);
			focusOnView();
			getData();
		}
			
	}
	public void onResume()
	{
		super.onResume();
		//focusOnView();
		findViewById(R.id.footer_info).setBackgroundResource(R.drawable.footer_clicked);
    	findViewById(R.id.footer_map).setBackgroundColor(Color.TRANSPARENT);
    	findViewById(R.id.footer_street_view).setBackgroundColor(Color.TRANSPARENT);
    	findViewById(R.id.footer_video).setBackgroundColor(Color.TRANSPARENT);
    	findViewById(R.id.footer_contact).setBackgroundColor(Color.TRANSPARENT);
	}
	private final void focusOnView(){
        new Handler().post(new Runnable() {
            @Override
            public void run() {
            	findViewById(R.id.title_scroll_view).scrollTo(findViewById(tv_id).getLeft()-10, 0);
            	
            }
        });
    }
	public void getData()
	{
		images.clear();
		parent_datas.clear();
		child_datas.clear();
		final ProgressDialog dialog = ProgressDialog.show(ViewActivity.this, null, 
    			getResources().getString(R.string.dialog_please_wait), true);
    	
    			final Handler handler_view = new Handler() {
    			   public void handleMessage(Message msg) {
    				   //RUN доторх үйлдэл хийгдэж дуусахад уншсан мэдээллүүдээ adapter-т хийж өгнө
    				   if(msg.what==1)
    				   {
    					   tv_name.setText(name);
    					   gal_adapter.notifyDataSetChanged();
        				   //gal_adapter=new GalleryAdapter(ViewActivity.this, images);
        				  // gallery.setAdapter(gal_adapter);
        				   //indicator.notify();
        				   //gallery.setFlowIndicator(indicator);
        				   //gal_adapter.notifyDataSetChanged();
        				   view_adapter = new MainExpandableAdapter(ViewActivity.this, parent_datas, null, child_datas, null);
        				   exp_view.setAdapter(view_adapter);
    				   }
    				   else
    					   Toast.makeText(ViewActivity.this, "Сервэртэй холбогдоход алдаа гарлаа", 3000).show();
    				   dialog.dismiss();
    			      }
    			   };
    			Thread checkUpdate = new Thread() {  
    			   public void run() {
    				   //энэ дотор Json-с дата уншиж харгалзах утгуудад нь хийж өгнө
    				   if(network.isConnectedToServer(getResources().getString(R.string.url_get_information)+b_id, 5000) && network.isNetworkConnected())
    				   {
        				   try {
        					   for(int i=0;i<3;i++)
        					   {
        						   parent_datas.add(parent_names[i]);
        					   }
        					   JSONfuncObject main_json_data = new JSONfuncObject();
        					   JSONObject json_data = main_json_data.getJSONfromURL(ViewActivity.this.getResources().getString(R.string.url_get_information)+b_id);
        					   Log.d("TEST", "json="+ViewActivity.this.getResources().getString(R.string.url_get_information)+b_id);
        					   JSONArray tsetserleg_array = json_data.getJSONArray(ViewActivity.this.getResources().getString(R.string.json_view_tsetserleg));
        					   JSONArray dundsurguuli_array = json_data.getJSONArray(ViewActivity.this.getResources().getString(R.string.json_view_dundsurguuli));
        					   JSONArray ihsurguuli_array = json_data.getJSONArray(ViewActivity.this.getResources().getString(R.string.json_view_ihsurguuli));
        					   name = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_name));
        					   body = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_body));
        					   price = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_price));
        					   lat = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_lat));
        					   lan = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_lan));
        					   streetimage = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_streetimage));
        					   video = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_video));
        					   holboobarih = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_contact));
        					   String[] room_image = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_image)).split(",");
        					   String[] bair_image = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_bairimg)).split(",");
        					   String room = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_image));
        					   String bair = json_data.getString(ViewActivity.this.getResources().getString(R.string.json_view_bairimg));
        					   if(room_image.length>0)
        						   image=room_image[0];
        					   else if(bair_image.length>0)
        						   image=bair_image[0];
        					   else
        						   image="";
        					   db.open();
        					   if(!db.isSaved(item_id))
        					   db.saveData(Integer.parseInt(b_id), name, body, price, image, room, bair, tsetserleg_array.toString(), 
        							   dundsurguuli_array.toString(), ihsurguuli_array.toString(), lat, lan, streetimage, video, holboobarih, category);
        					   db.close();
        					   tsetserleg = getResources().getString(R.string.item_info_tsetserleg)+"<br>";
        					   dundsurguuli = getResources().getString(R.string.item_info_dundsurguuli)+"<br>";
        					   ihsurguuli = getResources().getString(R.string.item_info_ihsurguuli)+"<br>";
        					   for(int i=0;i<tsetserleg_array.length();i++)
        					   {
        						   if(!tsetserleg_array.getString(i).equals(""))
        						   tsetserleg=tsetserleg+"&nbsp;&nbsp;&nbsp;"+tsetserleg_array.getString(i)+"<br>";
        					   }
        					   for(int i=0;i<dundsurguuli_array.length();i++)
        					   {
        						   if(!dundsurguuli_array.getString(i).equals(""))
        						   dundsurguuli=dundsurguuli+"&nbsp;&nbsp;&nbsp;"+dundsurguuli_array.getString(i)+"<br>";
        					   }
        					   for(int i=0;i<ihsurguuli_array.length();i++)
        					   {
        						   if(!ihsurguuli_array.getString(i).equals(""))
        						   ihsurguuli=ihsurguuli+"&nbsp;&nbsp;&nbsp;"+ihsurguuli_array.getString(i)+"<br>";
        					   }
        					   ArrayList<String> child1 = new ArrayList<String>();
        					   child1.add(body);
        					   ArrayList<String> child2 = new ArrayList<String>();
        					   child2.add(NumberFormat.getIntegerInstance().format(Long.parseLong(price)));
        					   ArrayList<String> child3 = new ArrayList<String>();
        					   child3.add(tsetserleg+"<br>"+dundsurguuli+"<br>"+ihsurguuli);
        					   child_datas.add(child1);
        					   child_datas.add(child2);
        					   child_datas.add(child3);
        					   
        					   
        					   for(int i=0;i<room_image.length;i++)
        					   {
        						   if(!room_image[i].equals("null") && !room_image[i].equals(""))
        						   images.add(ViewActivity.this.getResources().getString(R.string.url_room_image)+room_image[i]);
        					   }
        					   for(int i=0;i<bair_image.length;i++)
        					   {
        						   if(!bair_image[i].equals("null") && !bair_image[i].equals(""))
        						   images.add(ViewActivity.this.getResources().getString(R.string.url_baishin_image)+bair_image[i]);
        					   }
            				   
            				   
    					} catch (Exception e) {
    						// TODO: handle exception
    						Log.d("TEST", "error="+e);
    					}
        				   handler_view.sendEmptyMessage(1);
    				   }
    				   else
    					   handler_view.sendEmptyMessage(0);

    			      }
    			   };
    			checkUpdate.start();
	}
	public void loadDataFromDB()
	{
		images.clear();
		final ProgressDialog dialog = ProgressDialog.show(ViewActivity.this, null, 
    			getResources().getString(R.string.dialog_please_wait), true);
		final Handler handler_view = new Handler() {
			   public void handleMessage(Message msg) {
				   //RUN доторх үйлдэл хийгдэж дуусахад уншсан мэдээллүүдээ adapter-т хийж өгнө
				   tv_name.setText(name);
				   gal_adapter.notifyDataSetChanged();
				   //gal_adapter=new GalleryAdapter(ViewActivity.this, images);
				   //gallery.setAdapter(gal_adapter);
				   //gallery.setFlowIndicator(indicator);
				   //gal_adapter.notifyDataSetChanged();
				   view_adapter = new MainExpandableAdapter(ViewActivity.this, parent_datas, null, child_datas, null);
				   exp_view.setAdapter(view_adapter);
				   dialog.dismiss();
			      }
			   };
			Thread checkUpdate = new Thread() {  
			   public void run() {
				   //энэ дотор Json-с дата уншиж харгалзах утгуудад нь хийж өгнө
				   try {
					   db.open();
						name=db.getTitle(item_id);
						body=db.getBody(item_id);
						price=db.getPrice(item_id);
						lat=db.getLat(item_id);
						lan=db.getLan(item_id);
						streetimage=db.getStreetImage(item_id);
						video=db.getVideo(item_id);
						holboobarih=db.getContact(item_id);
						tsetserleg=db.getTsetserleg(item_id);
						dundsurguuli=db.getDundSurguuli(item_id);
						ihsurguuli=db.getIhSurguuli(item_id);
						room_image=db.getRoomImages(item_id);
						bair_image=db.getBairImages(item_id);
						db.close();
						String[] room_images = room_image.split(",");
						String[] bair_images = bair_image.split(",");
						JSONArray tsetserleg_array = null;
						JSONArray dundsurguuli_array = null;
						JSONArray ihsurguuli_array = null;
							try {
								 tsetserleg_array = new JSONArray(tsetserleg);
								 dundsurguuli_array = new JSONArray(dundsurguuli);
								 ihsurguuli_array = new JSONArray(ihsurguuli);
								 
								 tsetserleg = getResources().getString(R.string.item_info_tsetserleg)+"<br>";
								   dundsurguuli = getResources().getString(R.string.item_info_dundsurguuli)+"<br>";
								   ihsurguuli = getResources().getString(R.string.item_info_ihsurguuli)+"<br>";
								   for(int i=0;i<tsetserleg_array.length();i++)
								   {
									   if(!tsetserleg_array.getString(i).equals(""))
									   tsetserleg=tsetserleg+"&nbsp;&nbsp;&nbsp;"+tsetserleg_array.getString(i)+"<br>";
								   }
								   for(int i=0;i<dundsurguuli_array.length();i++)
								   {
									   if(!dundsurguuli_array.getString(i).equals(""))
									   dundsurguuli=dundsurguuli+"&nbsp;&nbsp;&nbsp;"+dundsurguuli_array.getString(i)+"<br>";
								   }
								   for(int i=0;i<ihsurguuli_array.length();i++)
								   {
									   if(!ihsurguuli_array.getString(i).equals(""))
									   ihsurguuli=ihsurguuli+"&nbsp;&nbsp;&nbsp;"+ihsurguuli_array.getString(i)+"<br>";
								   }
							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							
							for(int i=0;i<room_images.length;i++)
							   {
								   if(!room_images[i].equals("null") && !room_images[i].equals(""))
								   images.add(ViewActivity.this.getResources().getString(R.string.url_room_image)+room_images[i]);
							   }
							for(int i=0;i<bair_images.length;i++)
							   {
								   if(!bair_images[i].equals("null") && !bair_images[i].equals(""))
								   images.add(ViewActivity.this.getResources().getString(R.string.url_baishin_image)+bair_images[i]);
							   }
								ArrayList<String> child1 = new ArrayList<String>();
							   child1.add(body);
							   ArrayList<String> child2 = new ArrayList<String>();
							   child2.add(NumberFormat.getIntegerInstance().format(Long.parseLong(price)));
							   ArrayList<String> child3 = new ArrayList<String>();
							   child3.add(tsetserleg+"<br>"+dundsurguuli+"<br>"+ihsurguuli);
							   child_datas.add(child1);
							   child_datas.add(child2);
							   child_datas.add(child3);
							for(int i=0;i<3;i++)
						   {
							   parent_datas.add(parent_names[i]);
						   }
 				   handler_view.sendEmptyMessage(0);
 				   
				} catch (Exception e) {
					// TODO: handle exception
					Log.d("TEST", "error="+e);
				}
				   
			      }
			   };
			checkUpdate.start();
		

	}
	@Override
	public void onBackPressed() {
	   finish();
	   overridePendingTransition(R.anim.left_in, R.anim.right_out);
	}
	public void createTitleComponents()
	{
		//Хуудасны дээр байрлах толгой хэсгийн хийх үйлдлүүд
		
		//Үндсэн товчлууруудын үйлдэл
		//Буцах товчлуур
		findViewById(R.id.back).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
				overridePendingTransition(R.anim.left_in, R.anim.right_out);
			}
		});
		//Хадгалсан мэдээ унших товчлуур
		findViewById(R.id.title_history).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivity(new Intent(ViewActivity.this, ItemActivityFromDB.class));
				overridePendingTransition(R.anim.top_in, R.anim.no_anim);
			}
		});
		//Хайх товчлуур
		findViewById(R.id.title_search).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivity(new Intent(ViewActivity.this, SearchActivity.class));
				overridePendingTransition(R.anim.top_in, R.anim.no_anim);
			}
		});
		//Тухай товчлуур
		findViewById(R.id.title_info).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivity(new Intent(ViewActivity.this, InformationActivity.class));
				overridePendingTransition(R.anim.top_in, R.anim.no_anim);
			}
		});
		//Home буюу лого дээр дарах үйлдэл
		findViewById(R.id.home).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			}
		});
		findViewById(R.id.footer_map).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
            	findViewById(R.id.footer_info).setBackgroundColor(Color.TRANSPARENT);
            	findViewById(R.id.footer_map).setBackgroundResource(R.drawable.footer_clicked);
            	findViewById(R.id.footer_street_view).setBackgroundColor(Color.TRANSPARENT);
            	findViewById(R.id.footer_video).setBackgroundColor(Color.TRANSPARENT);
            	findViewById(R.id.footer_contact).setBackgroundColor(Color.TRANSPARENT);
            	
				Intent intent = new Intent(ViewActivity.this, ViewMapActivity.class);
				Bundle bundle = new Bundle();
				bundle.putInt("lat", (int)(Float.parseFloat(lat)*1e6));
				bundle.putInt("lon", (int)(Float.parseFloat(lan)*1e6));
				bundle.putString("strval", name+"<br>"+body);
				intent.putExtras(bundle);
				startActivity(intent);
				overridePendingTransition(R.anim.bottom_in, R.anim.no_anim);
			}
		});
		findViewById(R.id.footer_street_view).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(!streetimage.equals("") && !streetimage.contains("null") && streetimage != null)
				{
	            	findViewById(R.id.footer_info).setBackgroundColor(Color.TRANSPARENT);
	            	findViewById(R.id.footer_map).setBackgroundColor(Color.TRANSPARENT);
	            	findViewById(R.id.footer_street_view).setBackgroundResource(R.drawable.footer_clicked);
	            	findViewById(R.id.footer_video).setBackgroundColor(Color.TRANSPARENT);
	            	findViewById(R.id.footer_contact).setBackgroundColor(Color.TRANSPARENT);
	            	
					Intent intent = new Intent(ViewActivity.this, PanoramaActivity.class);
					Bundle bundle = new Bundle();
					bundle.putString("image", "http://202.131.237.185/ubzuuch/web/uploads/images/street/"+streetimage);
					intent.putExtras(bundle);
					startActivity(intent);
					overridePendingTransition(R.anim.bottom_in, R.anim.no_anim);
				}
				else
					Toast.makeText(ViewActivity.this, "Гудамжны зураг олдсонгүй", 2000).show();
				
			}
		});
		findViewById(R.id.footer_video).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(!video.equals("") && !video.equals("null") && video != null)
				{
	            	findViewById(R.id.footer_info).setBackgroundColor(Color.TRANSPARENT);
	            	findViewById(R.id.footer_map).setBackgroundColor(Color.TRANSPARENT);
	            	findViewById(R.id.footer_street_view).setBackgroundColor(Color.TRANSPARENT);
	            	findViewById(R.id.footer_video).setBackgroundResource(R.drawable.footer_clicked);
	            	findViewById(R.id.footer_contact).setBackgroundColor(Color.TRANSPARENT);
	            	
					String videoId = video.substring(video.indexOf("embed/")+6, video.length());
					videoId=videoId.substring(0, videoId.indexOf("\""));
					Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"+videoId)); 
					intent.putExtra("VIDEO_ID", videoId); 
					startActivity(intent); 
				}
				else
				{
					Toast.makeText(ViewActivity.this, "Видео байхгүй байна", 2000).show();
				}
				
			}
		});
		findViewById(R.id.footer_contact).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

            	findViewById(R.id.footer_info).setBackgroundColor(Color.TRANSPARENT);
            	findViewById(R.id.footer_map).setBackgroundColor(Color.TRANSPARENT);
            	findViewById(R.id.footer_street_view).setBackgroundColor(Color.TRANSPARENT);
            	findViewById(R.id.footer_video).setBackgroundColor(Color.TRANSPARENT);
            	findViewById(R.id.footer_contact).setBackgroundResource(R.drawable.footer_clicked);
            	
				Intent intent = new Intent(ViewActivity.this, ContactUsActivity.class); 
				Bundle bundle = new Bundle();
				bundle.putString("contact", "Contact us");
				intent.putExtras(bundle);
				startActivity(intent);
				overridePendingTransition(R.anim.bottom_in, R.anim.no_anim);
				
			}
		});
		
		//Програмын үндсэн менюны үйлдлүүд
		findViewById(R.id.title_menu_1).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				va.finish();
				Intent intent = new Intent(ViewActivity.this, MainActivity.class); 
				intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); 
				startActivity(intent);
				finish();
				overridePendingTransition(R.anim.left_in, R.anim.right_out);
			}
		});
		findViewById(R.id.title_menu_2).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				va.finish();
				Intent intent = new Intent(ViewActivity.this, RentActivity.class); 
				intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); 
				startActivity(intent);
				finish();
				overridePendingTransition(R.anim.left_in, R.anim.right_out);
			}
		});
		findViewById(R.id.title_menu_3).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				va.finish();
				Intent intent = new Intent(ViewActivity.this, NewApartmentActivity.class); 
				intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); 
				startActivity(intent);
				finish();
				overridePendingTransition(R.anim.left_in, R.anim.right_out);
			}
		});
		findViewById(R.id.title_menu_4).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				va.finish();
				Intent intent = new Intent(ViewActivity.this, UBActivity.class); 
				intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); 
				startActivity(intent);
				finish();
				overridePendingTransition(R.anim.left_in, R.anim.right_out);
			}
		});
		findViewById(R.id.title_menu_5).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				va.finish();
				Intent intent = new Intent(ViewActivity.this, AutomobileActivity.class); 
				intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); 
				startActivity(intent);
				finish();
				overridePendingTransition(R.anim.left_in, R.anim.right_out);
			}
		});
	}
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
	    setContentView(R.layout.item_view);
	    initialize();
	    super.onConfigurationChanged(newConfig);
	}
	public void initialize()
	{
		va=ItemActivity.ia;
		network=new NetworkConnectionClass(this);
		Bundle bundle = getIntent().getExtras();
		tv_id = bundle.getInt("title");
		isFromFB = bundle.getBoolean("isfromdb");
		if(tv_id==R.id.title_menu_1)
			category="1";
		else if(tv_id==R.id.title_menu_2)
			category="2";
		else if(tv_id==R.id.title_menu_3)
			category="3";
		b_id = bundle.getString("id");
		item_id=Integer.parseInt(b_id);
		exp_view = (ExpandableListView)findViewById(R.id.view_screen_exp);
		exp_view.setGroupIndicator(null);
		exp_view.setOnGroupExpandListener(new OnGroupExpandListener() {
			
			@Override
			public void onGroupExpand(int groupPosition) {
				// TODO Auto-generated method stub
				for(int i=0;i<parent_datas.size();i++)
				{
					if(groupPosition!=i)
						exp_view.collapseGroup(i);
					//else
						
				}
			}
		});
		gallery = (ViewFlow)findViewById(R.id.view_screen_viewflow);
		indicator = (CircleFlowIndicator) findViewById(R.id.view_screen_indicator);
		gallery.setOnViewSwitchListener(new ViewSwitchListener() {
			
			@Override
			public void onSwitched(View view, int position) {
				// TODO Auto-generated method stub
				gal_pos=position;
			}
		});
		gal_adapter=new GalleryAdapter(this, images);
		gallery.setAdapter(gal_adapter);
		gallery.setFlowIndicator(indicator);
		full_screen = (TextView)findViewById(R.id.view_screen_fullscreen);
		full_screen.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(images.size()==0)
				{
					Toast.makeText(ViewActivity.this, "Зураггүй байна", 2000).show();
				}
				else
				{
					Intent intent = new Intent(ViewActivity.this, GalleryView.class);
					Bundle bundle = new Bundle();
					bundle.putInt("pos", gal_pos);
					bundle.putStringArrayList("array", images);
					intent.putExtras(bundle);
					startActivity(intent);
					overridePendingTransition(R.anim.right_in, R.anim.no_anim);
				}
			}
		});
		tv_name=(TextView)findViewById(R.id.view_screen_name);
		createTitleComponents();
		   tv_name.setText(name);
		   //gal_adapter=new GalleryAdapter(ViewActivity.this, images);
		   //gallery.setAdapter(gal_adapter);
		   //gallery.setFlowIndicator(indicator);
		   //gal_adapter.notifyDataSetChanged();
		   view_adapter = new MainExpandableAdapter(ViewActivity.this, parent_datas, null, child_datas, null);
		   exp_view.setAdapter(view_adapter);
	}

}
